
package com.studiofortress.sf.util.structure;

import com.studiofortress.sf.graphics.GraphicsGL;
import com.studiofortress.sf.graphics.display.GraphicsDisplay;
import com.studiofortress.sf.structure.MainLoop;

/**
 * The same as a MainLoop only this runs in a seperate thread and so returns
 * when the run method is called.
 * 
 * @author Joseph Lenton - JL235@Kent.ac.uk
 */
public class NonBlockingMainLoop<G extends GraphicsGL> extends MainLoop<G>
{
    public NonBlockingMainLoop(GraphicsDisplay display)
    {
        super( display );
    }
    
    /**
     * This will start running in a different thread.
     */
    @Override
    public void run()
    {
        Thread runThread = new Thread() {
            @Override
            public void run()
            {
                NonBlockingMainLoop.super.run();
            }
        };
        runThread.start();
        
        // this is to encourage the thread we just started to run
        Thread.yield();
    }
}
